package jdbc_firstlook;

import java.sql.*;

// 0、创建工程，导入驱动jar包
public class JDBC_UserLogin_Insert {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //2、获取连接
        String url = "jdbc:mysql:///itcase?useSSL = false";
        String username = "root";
        String password = "202111a.";
        Connection conn = DriverManager.getConnection(url,username,password);


        //接收用户输入用户名和密码
        String name = "abc";
        String pwd = "' or '1' = '1";

        String sql = "select * from stu where username = '"+name+"' and password = '"+pwd+"'";

        //获取对象
        Statement stmt = conn.createStatement();
        //执行SQL
        ResultSet rs = stmt.executeQuery(sql);
        //判断登录是否成功
        if(rs.next()){
            System.out.println("登录成功");
        }else {
            System.out.println("登陆失败");
        }

        //7、释放资源
        conn.close();
        stmt.close();
    }
}
